package com.wangdao.wechatmall.service.admin;

import com.github.pagehelper.PageInfo;
import com.wangdao.wechatmall.bean.bo.admin.FeedbackListBO;
import com.wangdao.wechatmall.bean.pojo.Feedback;
import com.wangdao.wechatmall.bean.pojo.FeedbackExample;
import com.wangdao.wechatmall.bean.vo.admin.BaseDataVO;
import com.wangdao.wechatmall.mapper.FeedbackMapper;
import com.wangdao.wechatmall.util.MyPageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ZhangXiao on 2021/7/9
 */
@Service
public class FeedbackListServiceImpl implements FeedbackListService {
    @Autowired
    FeedbackMapper feedbackMapper;

    @Override
    public BaseDataVO<Feedback> queryFeedbackList(FeedbackListBO feedbackListBO) {
        MyPageHelper.startPage(feedbackListBO);
        FeedbackExample feedbackExample = new FeedbackExample();
        FeedbackExample.Criteria criteria = feedbackExample.createCriteria();
        Integer id = feedbackListBO.getId();
        String username = feedbackListBO.getUsername();

        if (id != null && id != ' ') {
            criteria.andIdEqualTo(id);
        }
        if (username != null && !"".equals(username)) {
            criteria.andUsernameLike("%" + username + "%");
        }

        feedbackExample.setOrderByClause(feedbackListBO.getSort() + " " + feedbackListBO.getOrder());

        List<Feedback> feedbacks = feedbackMapper.selectByExample(feedbackExample);

        PageInfo<Feedback> feedbackPageInfo = new PageInfo<>(feedbacks);
        long total = feedbackPageInfo.getTotal();

        return BaseDataVO.ok(feedbacks, total);
    }
}
